package brian.android.mvc.event;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import android.util.Log;
import android.view.ContextMenu;
import android.view.View;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.View.OnCreateContextMenuListener;

public class OnCreateContextMenuEventHandler extends AbstactEventHandler implements EventHandler, OnCreateContextMenuListener {
	@SuppressWarnings("unchecked")
	protected Class getEventListener() {
		return OnCreateContextMenuListener.class;
	}

	@Override
	public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
		Method eventMethod = getEventMethod();
		List<Object> argViews = getArguments(eventMethod, new Object[]{menu, view, menuInfo}, new Class[]{menu.getClass(), view.getClass(), menuInfo.getClass()});
		try {
			eventMethod.invoke(getActivity(), argViews.toArray());
		} catch (IllegalArgumentException e) {
			Log.e(this.getClass().getSimpleName(), "Error[" + getEventMethod().getName() + "]", e);
		} catch (IllegalAccessException e) {
			Log.e(this.getClass().getSimpleName(), "Error[" + getEventMethod().getName() + "]", e);
		} catch (InvocationTargetException e) {
			Log.e(this.getClass().getSimpleName(), "Error[" + getEventMethod().getName() + "]", e);
		}
	}
}
